﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Boggle.TheGame
{

    /// <summary>
    /// Used for DFS search, stores its depth (if depth is 4 and it doesn't have a key, I can abandon the path)
    /// as well as the string it contains (which is a combination of a given value and its parents, which is likewise.)
    /// </summary>
    class PathNode
    {
        PathNode parent;
        string content;
        int depth;
        int row;
        int column;

        #region properties

        public int Row
        {
            get { return row; }
        }

        public int Column
        {
            get { return column; }
        }

        public string Content
        {
            get { return content; }
        }

        public int Depth
        {
            get { return depth; }
        }

        public PathNode Parent
        {
            get { return parent; }
        }

        #endregion

        /// <summary>
        /// Creates a PathNode, which will either be the top (have no parent) and have a depth of 1
        /// and start a string, or else take its parents string, include its given string, and have its parent's
        /// depth + 1. 
        /// </summary>
        /// <param name="parent">PathNode that is a parent, null if first node.</param>
        /// <param name="content">Letter(s) of the dice being traveled to on the board.</param>
        /// <param name="row">Row of the tile that this pathnode is being created from</param>
        /// <param name="column">Column of the tile that this pathnode is being created from.</param>
        public PathNode(PathNode parent, string content, int row, int column)
        {
            this.row = row;
            this.column = column;

            if (parent == null)
            {
                this.parent = null;
                depth = 1;
                this.content = content;
            }
            else
            {
                this.parent = parent;
                depth = parent.Depth + 1;
                this.content = parent.Content + content;
            }
        }

        public bool IsBelow(PathNode toCheck)
        {
            PathNode current = this;

            if (toCheck.Row == current.Row && toCheck.Column == current.Column)
            {
                return true;
            }


            if (current.Parent == null)
            {
                return false;
            }

            while (!(toCheck.Row == current.Row) && !(toCheck.Column == current.Column))
            {
                    current = current.Parent;

                    if (current.Parent == null)
                    {
                        return false;
                    }
            }

            return true;
                
        }

    }
}
